﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="Myproject.BSM.index" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>系统登录</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="/bsm/BJUI/otherCSS/loginstyle.css" rel="stylesheet" />
</head>
<body>
    <div class="wrapper">
        <div class="content">
            <div id="form_wrapper" class="form_wrapper">
                <form class="login active">
                    <h3>后台登录</h3>
                    <div>
                        <label>账号:</label>
                        <input type="text" id="loginname" />
                        <span class="error" id="loginnamerror"></span>
                    </div>
                    <div>
                        <label>密码: <a href="#" rel="forgot_password" class="forgot linkform">忘记密码?</a></label>
                        <input type="password"  id="loginpwd" />
                        <span class="error" id="loginpwderror"></span>
                    </div>
                    <div class="bottom">
                        <input type="submit" value="登录" id="loginbtn"/>
                        <div class="clear"></div>
                    </div>
                </form>
                <form class="forgot_password">
                    <h3>找回密码</h3>
                    <div>
                        <label>登录账号:</label>
                        <input type="text" id="fandUser" />
                        <span class="error" id="fandUsererror"></span>
                    </div>
                    <div>
                        <label>绑定邮箱:</label>
                        <input type="text" id="fandEmail" />
                        <span class="error" id="fandEmailerror"></span>
                    </div>
                    <div class="bottom">
                        <input type="submit" id="dendemail" value="发送邮件" />
                        <a href="#" rel="login" class="linkform">返回登录</a>
                        <div class="clear"></div>
                    </div>
                </form>
            </div>
            <div class="clear"></div>
        </div>
    </div>


    <!-- The JavaScript -->
    <script src="BJUI/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var $form_wrapper = $('#form_wrapper'),
                $currentForm = $form_wrapper.children('form.active'),
                $linkform = $form_wrapper.find('.linkform');
				
            $form_wrapper.children('form').each(function (i) {
                var $theForm = $(this);
                if (!$theForm.hasClass('active'))
                    $theForm.hide();
                $theForm.data({
                    width: $theForm.width(),
                    height: $theForm.height()
                });
            });

            setWrapperWidth();

            $linkform.bind('click', function (e) {
                var $link = $(this);
                var target = $link.attr('rel');
                $currentForm.fadeOut(400, function () {
                    $currentForm.removeClass('active');
                    $currentForm = $form_wrapper.children('form.' + target);
                    $form_wrapper.stop()
                                 .animate({
                                     width: $currentForm.data('width') + 'px',
                                     height: $currentForm.data('height') + 'px'
                                 }, 500, function () {
                                     $currentForm.addClass('active');
                                     $currentForm.fadeIn(400);
                                 });
                });
                e.preventDefault();
            });

            function setWrapperWidth() {
                $form_wrapper.css({
                    width: $currentForm.data('width') + 'px',
                    height: $currentForm.data('height') + 'px'
                });
            }

            $form_wrapper.find('input[type="submit"]')
                         .click(function (e) {
                             e.preventDefault();
                         });
        });

        var wait = 60;
        function time(o) {
            if (wait == 0) {
                o.removeAttribute("disabled");
                document.getElementById("fandUser").removeAttribute("disabled");
                document.getElementById("fandEmail").removeAttribute("disabled");
                o.value = "重新发送";
                wait = 60;
            }
            else {
                o.setAttribute("disabled", true);
                document.getElementById("fandUser").setAttribute("disabled", true);
                document.getElementById("fandEmail").setAttribute("disabled", true);
                o.value = "重新发送(" + wait + ")";
                wait--;
                setTimeout(function () {
                    time(o)
                },
                1000)
            }
        }
        document.getElementById("dendemail").onclick = function () {
            var returnFlag = false;
            if ($("#fandUser").val() == "") {
                $("#fandUsererror").html("账号不能为空！");
                returnFlag = true;
            }
            else {
                $("#fandUsererror").html("");
            }
            if ($("#fandEmail").val() == "") {
                $("#fandEmailerror").html("绑定邮箱不能为空！");
                returnFlag = true;
            }
            else {
                $("#fandEmailerror").html("");
            }
            if (returnFlag) return;
            //验证邮箱，用户名
            //alert("发送邮件");
            $.ajax({
                type: "post",
                url: "/bsm/ashx/SendEmail.ashx?userLoginName=" + $("#fandUser").val() + "&email=" + $("#fandEmail").val(),
                dataType: "json",
                beforeSend: function (XMLHttpRequest) {
                },
                success: function (data) {
                    if (data.IsError) {
                        alert("发送邮件成功，请注意查收！成功登陆后建议再次修改密码");
                    }
                    else {
                        alert(data.Message);
                    }
                },
                error: function () {

                }
            });
            time(this);
        }

        $("#loginbtn").click(function () {
            var returnFlag = false;
            if ($("#loginname").val() == "") {
                $("#loginnamerror").html("账号不能为空！");
                returnFlag = true;
            }
            else {
                $("#loginnamerror").html("");
            }
            if ($("#loginpwd").val() == "") {
                $("#loginpwderror").html("密码不能为空！");
                returnFlag = true;
            }
            else {
                $("#loginpwderror").html("");
            }
            if (returnFlag) return;

            $.ajax({
                type: "post",
                url: "/bsm/ashx/load.ashx?loginname=" + $("#loginname").val() + "&loginpwd=" + $("#loginpwd").val(),
                dataType: "json",
                beforeSend: function (XMLHttpRequest) {
                    document.getElementById("loginname").setAttribute("disabled", true);
                    document.getElementById("loginpwd").setAttribute("disabled", true);
                    document.getElementById("loginbtn").setAttribute("disabled", true);
                    document.getElementById("loginbtn").value = "正在登录...";
                },
                success: function (data) {
                    if (data.IsError) {
                        document.getElementById("loginbtn").value = "登录成功...";
                        window.location.href = '/bsm/main.aspx';
                    }
                    else {
                        document.getElementById("loginname").removeAttribute("disabled");
                        document.getElementById("loginpwd").removeAttribute("disabled");
                        document.getElementById("loginbtn").removeAttribute("disabled");
                        document.getElementById("loginbtn").value = "重新发送";
                        if (data.Message == "账号不存在") {
                    //alert(data.Message);
                            $("#loginnamerror").html("账号不存在");
                        }
                        else {
                            $("#loginpwderror").html("密码错误");
                        }
                    }
                },
                error: function () {
                    document.getElementById("loginname").removeAttribute("disabled");
                    document.getElementById("loginpwd").removeAttribute("disabled");
                    document.getElementById("loginbtn").removeAttribute("disabled");
                    document.getElementById("loginbtn").value = "重新发送";

                }
            });
        });

    </script>
</body>
</html>
